package com.dolphin.apidriver.controller;

import com.dolphin.apidriver.service.UserService;
import com.dolphin.common.dto.DriverUser;
import com.dolphin.common.dto.DriverUserWorkStatus;
import com.dolphin.common.dto.ResponseResult;
import com.dolphin.common.dto.TokenResult;
import com.dolphin.common.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @PutMapping("/user")
    public ResponseResult updateUser(@RequestBody DriverUser driverUser){
        log.info("service-driver-user:driverUser:"+ JSONObject.fromObject(driverUser).toString());
        return userService.updateUser(driverUser);
    }
    @PostMapping("/driver-user-work-status")
    public ResponseResult changeWorkStatus(@RequestBody DriverUserWorkStatus driverUserWorkStatus){
        return userService.changeWorkStatus(driverUserWorkStatus);
    }

    /**
     * 根据司机token查看司机和车辆绑定信息
     * @param request
     * @return
     */

    @GetMapping("/driver-car-binding-relationship")
    public ResponseResult getDriverCarBindingRelationship(HttpServletRequest request) {
        String authorization = request.getHeader("Authorization");
        TokenResult tokenResult = JwtUtils.checkToken(authorization);
        String driverPhone = tokenResult.getPhone();
        return userService.getDriverCarBindingRelationship(driverPhone);

    }
}
